import { useState,useEffect } from 'react';

function App() {
  let [num,setNum]=useState(1);
  const [age,setAge]=useState(18);
  async function queryData() {
   const data = await new Promise((resolve)=>{
    setTimeout(()=>{
      resolve(666)
    },2000)
   })
   return data;
  }
  useEffect(()=>{
    console.log('num值改变了')
    let timer = setInterval(()=>{
      setNum(num)
    },1000)
    return ()=>{
      console.log('组件卸载了')
      clearInterval(timer)
    }
  },[num])
  function handle(){
    setNum(num+1)
  }
  return (
    <div>
      <button onClick={handle}>{num}</button>
      <h2 onClick={()=>setAge(age+1)}>{age}</h2>
    </div>
  );
}
export default App;
